var pinyin = require('pinyin');
var _ = require('underscore');

// 给每行新增一条pinyin的记录，并且按照拼音进行排序
exports.formatData = function(datas,key){
  for(i in datas){
    var data = datas[i];
    if(data[key]){
      data.pinyin = pinyin(data.name,{style:pinyin.STYLE_NORMAL}).toString();
    }
  }
  var result = _.sortBy(datas,'pinyin');
  return result;
}